home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / utility-src / cat.c next >
Encoding:
C/C++ Source or Header  |  1994-03-04  |  898 b   |  49 lines  |  [TEXT/EMAC]

  1. /*
  2.  * Copyright (C) 1993, 1994 Marc Parmet.
  3.  * This file is part of the Macintosh port of GNU Emacs.
  4.  *
  5.  * GNU Emacs is distributed in the hope that it will be useful,
  6.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8.  * GNU General Public License for more details.
  9.  */
  10.  
  11. #include "stdio.h"
  12.  
  13. static void
  14. cat_file(FILE *fp,char *fname)
  15. {
  16.     static int i = 0;
  17.     register char c;
  18.  
  19.     if (fname) {
  20.         if (i++ > 0) printf("\n");
  21.         printf("%s:\n",fname);
  22.     }
  23.  
  24.     while ((c = getc(fp)) != EOF)
  25.         putchar(c);
  26. }
  27.  
  28. int
  29. main(int argc,char **argv)
  30. {
  31.     int k;
  32.     
  33.     if (argc == 1)
  34.         cat_file(stdin,0L);
  35.     else
  36.         for (k = 1; k<argc; ++k) {
  37.             char *fname = argv[k];
  38.             FILE *fp = fopen(fname,"r");
  39.             if (fp == 0L) {
  40.                 printf("%s: file '%s' not found\n",argv[0],fname);
  41.                 continue;
  42.             }
  43.             cat_file(fp,fname);
  44.             fclose(fp);
  45.         }
  46.  
  47.     return 0;
  48. }
  49.